﻿@{
    ViewBag.Title = "门诊退费确认";
    Layout = "~/Views/Shared/_Index.cshtml";
}

<style type="text/css">
    #divTmx .panel-heading {
        background-color: #fcfbfb !important;
    }

        #divTmx .panel-heading span {
            margin-right: 15px;
            font-weight: bold;
            line-height: 20px;
        }

    #divTmx #tje {
        font-weight: bold;
    }

    #divTmx ul li {
        margin-left: 0;
        font-size: 14px;
        line-height: 24px;
    }
</style>

<div style="vertical-align:middle;">
    <div id="divTmx">
        <div class="panel panel-default" style="margin: 20px;">
            <div class="panel-heading navb-bg">
                <span>结算时间：<span id="settTime"></span></span>
                <span>结算金额：<span id="zje"></span></span>
                <span>支付金额：<span id="xjzf"></span></span>
                <br />
                <span>支付方式：<span id="xjzffsmc"></span></span>
                <span>收费日期：<span id="sfrq"></span></span>
            </div>
            <div style="padding-right:20px;">
                <table class="form">
                    <thead>
                        <tr>
                            <td class="formValue" style="padding-left:10px;">
                                退费明细
                            </td>
                            <td class="formValue" style="width:160px;">
                                名称
                            </td>
                            <td class="formValue">
                                单价
                            </td>
                            <td class="formValue">
                                数量
                            </td>
                            <td class="formValue">
                                退数量
                            </td>
                            <td class="formValue">
                                退金额
                            </td>
                        </tr>
                    </thead>
                    <tbody></tbody>
                </table>
            </div>
        </div>
        <div style="margin: 20px;">
            <ul class="nav nav-pills" style="position: fixed;right: 80px;bottom: 20px;">
                <li>退费人员：<span>@(Newtouch.Common.Operator.OperatorProvider.GetCurrent().UserName)</span></li>
                <li>退费日期：<span>@(DateTime.Now.ToString("yyyy-MM-dd"))</span></li>
                <li>退费时间：<span>@(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))</span></li>
                <li>合计退费：<span id="tje"></span></li>
            </ul>
        </div>
    </div>
</div>
<script type="text/javascript">
    var thisJszb = sessionStorage.getItem("needRefundJszb");
    var data = sessionStorage.getItem("needRefundData");
    var mzh = $.request("mzh");
    if (!!thisJszb || !!data) {
        var thisJszb = JSON.parse(thisJszb);
        var data = JSON.parse(data);
    }

    $(function () {
        if (!!!thisJszb || !!!data) {
            return;
        }
        $('#settTime').html($.getTime({ date: thisJszb.CreateTime }));
        var zje = thisJszb.jszje;
        $('#zje').html(thisJszb.jszje ? thisJszb.jszje.toFixed(2) : '');
        $('#xjzf').html(thisJszb.jsxjzf ? thisJszb.jsxjzf.toFixed(2) : '');
        $('#sfrq').html($.getDate({ date: thisJszb.sfrq }));
        $('#xjzffsmc').html(thisJszb.xjzffsmc);

        var tmxZje = 0;
        $.each(data, function () {
            var mxtje = this.dj * this.tsl;
            tmxZje += mxtje;
            $('#divTmx table tbody').append('<tr><td class="formValue"></td><td class="formValue">' + this.mc + '</td><td class="formValue">' + this.dj + '</td><td class="formValue">' + this.sl + '</td><td class="formValue">' + this.tsl + '</td><td class="formValue">' + roundingBy4she6ru5chengshuang(mxtje, 2) + '</td></tr>');
        });
        var strTje = roundingBy4she6ru5chengshuang(tmxZje, 2);
        if (thisJszb.jszje == tmxZje && thisJszb.jsxjzf != thisJszb.jszje) {
            //非全自费结算记录
            strTje += '（实退' + thisJszb.jsxjzf.toFixed(2) + '）';
        }
        if (thisJszb.xjzffsmc === '支付宝' || thisJszb.xjzffsmc === '微信') {
            strTje += '（原路退回）';
        }
        $('#tje').html(strTje);
    });

    function AcceptClick(callBack) {
        var postData = {};
        postData.mzh = mzh;
        postData.jsnm = thisJszb.jsnm;
        var tjsxmDictObj = {};
        var tjsxmDictZtObj = {};//收费组套
        var expectedTmxZje = 0;
        var expectedTmxZtZje = 0;//收费组套金额
        var cfnmlist = ""; //组套所属处方
        debugger
        $.each(data, function () {
            if (this.ztId) {
                tjsxmDictZtObj[this.ztId] = this.tsl;
                expectedTmxZtZje += this.dj * this.tsl;
                cfnmlist += this.cfnm + ",";
            }
            else {
                tjsxmDictObj[this.jsmxnm] = this.tsl;
                expectedTmxZje += this.dj * this.tsl;
            }
            
        });
        if (expectedTmxZje > 0) {
            postData.tjsxmDict = tjsxmDictObj;
        }
        else {
            postData.tjsxmDictZt = tjsxmDictZtObj;
        }
        if (tjsxmDictZtObj != "" || tjsxmDictZtObj != null) {
            postData.tjsxmDictZt = tjsxmDictZtObj;
        }
        postData.expectedTmxZje = ovpraseFloat(expectedTmxZje).toFixed(4);
        postData.expectedTmxZjeZt = ovpraseFloat(expectedTmxZtZje).toFixed(4);
        postData.cfnmArray = cfnmlist;
        $.submitForm({
            url: "/OutpatientManage/OutpatientRefund/RefundSettlement",
            param: postData,
            success: function(ajaxResp) {
                callBack(ajaxResp);
                
                $.modalClose();
            }
        });
    }
    function ovpraseFloat(val) {
        if (!val) {
            val = 0.00;
        }
        return parseFloat(val);
    }
</script>
